//
//  AppDelegate.m
//  GameBoss
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "LatestViewController.h"
#import "PictureViewController.h"
#import "VideoViewController.h"
#import "SettingViewController.h"
#import "AFNetworking.h"
#import <ShareSDK/ShareSDK.h>
#import "WeiboSDK.h"
#import "WXApi.h"
#import <TencentOpenAPI/QQApi.h>
//#import <TencentOpenAPI/QQApiInterface.h>
//#import <TencentOpenAPI/TencentOAuth.h>
#import <QZoneConnection/QZoneConnection.h>
#import "EquipmentViewController.h"

#import <RennSDK/RennSDK.h>


#import "startAnimationViewController.h"

#define ScreenSize ([UIScreen mainScreen].bounds.size.width / 8)




@interface AppDelegate ()

// 开机动画的scrollview
@property(nonatomic, retain) UIImageView *starAnimationView;




@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//    self.window.backgroundColor = [UIColor whiteColor];
    NSDate *a=[[NSDate alloc] init];
    NSLog(@"%.f", a.timeIntervalSince1970);
    
#pragma mark 开启数据库
    [[DataCache shareDataCache] openDB];
#pragma mark 创建表
    [[DataCache shareDataCache] createTable:@"latesTable"];
    [[DataCache shareDataCache] createTable:@"pictureTable"];
    [[DataCache shareDataCache] createTable:@"videoTable"];
#pragma mark 开机图片时间
    [NSThread sleepForTimeInterval:3.0];
    
#pragma mark latestViewController
    LatestViewController * latestViewController = [[LatestViewController alloc] init];
    UINavigationController *navigationControllerLatest  = [[UINavigationController alloc] initWithRootViewController:latestViewController];
    navigationControllerLatest.navigationBar.tintColor = [UIColor whiteColor];
    navigationControllerLatest.navigationBar.translucent = NO;

#pragma mark 设置navigationBar颜色
    navigationControllerLatest.navigationBar.barTintColor =[UIColor colorWithRed:116/255.0 green:117/255.0 blue:147/255.0 alpha:1];
    latestViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"资讯" image:[UIImage imageNamed:@"iconfont-zuixinzixunicon-2"] selectedImage:[UIImage imageNamed:@"g"]];
    
#pragma mark pictureViewController
    PictureViewController *pictureViewController = [[PictureViewController alloc] init];
    UINavigationController *navigationControllerPic = [[UINavigationController alloc]initWithRootViewController:pictureViewController];
    navigationControllerPic.navigationBar.tintColor = [UIColor whiteColor];
    navigationControllerPic.navigationBar.barTintColor = [UIColor colorWithRed:116/255.0 green:117/255.0 blue:147/255.0 alpha:1];
#pragma mark 设置navigationBar 为黑色
//    navigationControllerPic.navigationBar.barStyle = UIBarStyleBlackTranslucent;
//    navigationControllerPic.extendedLayoutIncludesOpaqueBars = YES;
    navigationControllerPic.navigationBar.translucent = NO;
    pictureViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"图片" image:[UIImage imageNamed:@"iconfont-tupian"] selectedImage:[UIImage imageNamed:@"a"]];

#pragma mark videlViewController
    VideoViewController *videlViewController = [[VideoViewController alloc] init];
    UINavigationController *navigationControllerVi = [[UINavigationController alloc]initWithRootViewController:videlViewController];
    navigationControllerVi.navigationBar.tintColor = [UIColor whiteColor];
    navigationControllerVi.navigationBar.barTintColor = [UIColor colorWithRed:116/255.0 green:117/255.0 blue:147/255.0 alpha:1];
    navigationControllerVi.navigationBar.translucent = NO;
    videlViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视频" image:[UIImage imageNamed:@"iconfont-shipin"] selectedImage:[UIImage imageNamed:@"m"]];
    
#pragma mark settingViewController
    SettingViewController *settingViewController = [[SettingViewController alloc] init];
    UINavigationController *navigationControllerSet = [[UINavigationController alloc]initWithRootViewController:settingViewController];
    navigationControllerSet.navigationBar.tintColor = [UIColor whiteColor];
    navigationControllerSet.navigationBar.barTintColor = [UIColor colorWithRed:116/255.0 green:117/255.0 blue:147/255.0 alpha:1];
    navigationControllerSet.navigationBar.translucent = NO;
    navigationControllerSet.title = @"设置";
    settingViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"iconfont-shezhi"] tag:1003];
    
#pragma mark equipmentViewController
    EquipmentViewController *equipmentViewController = [[EquipmentViewController alloc] init];
    UINavigationController *navigationEquipment = [[UINavigationController alloc] initWithRootViewController:equipmentViewController];
    navigationEquipment.navigationBar.tintColor = [UIColor whiteColor];
    navigationEquipment.navigationBar.barTintColor = [UIColor colorWithRed:116/255.0 green:117/255.0 blue:147/255.0 alpha:1];
    navigationEquipment.navigationBar.translucent = NO;
    navigationEquipment.title = @"设备";
    equipmentViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"设备" image:[UIImage imageNamed:@"equipment"] selectedImage:[UIImage imageNamed:@"e"]];
 
    UITabBarController *tabBarC = [[UITabBarController alloc] init];
  
#pragma mark tabBar背景图
//    tabBarC.tabBar.backgroundImage = [UIImage imageNamed:@"wuqi3"];
//    tabBarC.tabBar.backgroundImage.
//    imageView.contentMode = UIViewContentModeScaleAspectFit;
//    imageView.autoresizesSubviews = YES;
    tabBarC.tabBar.translucent = NO;
    tabBarC.tabBar.barTintColor =[UIColor colorWithRed:116/255.0 green:117/255.0 blue:147/255.0 alpha:1];
    tabBarC.viewControllers = [NSArray arrayWithObjects:navigationControllerLatest, navigationControllerPic, navigationControllerVi,navigationEquipment,navigationControllerSet ,nil];
    
    self.window.rootViewController = tabBarC;
    [self.window makeKeyAndVisible];
    
#pragma mark 第三方分享
    [ShareSDK registerApp:@"6f8275973868"];
    [self initializePlat];
#pragma mark 第三方登录


    
    startAnimationViewController *startView = [[startAnimationViewController alloc] init];
    if ([startView isFirstOpen])
    {
//        tabBarC.tabBar.hidden = YES;
        [self.window addSubview:startView.view];
        [startView firstOpened];
    }
    
    [latestViewController release];
    [navigationControllerLatest release];
    [pictureViewController release];
    [navigationControllerPic release];
    [videlViewController release];
    [navigationControllerVi release];
    [settingViewController release];
    [navigationControllerSet release];


    [tabBarC release];
   
    [_window release];
    
    return YES;
}



- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}
- (void)initializePlat
{
    /**
     连接新浪微博开放平台应用以使用相关功能，此应用需要引用SinaWeiboConnection.framework
     http://open.weibo.com上注册新浪微博开放平台应用，并将相关信息填写到以下字段
     **/
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];
    
    /**
     连接人人网应用以使用相关功能，此应用需要引用RenRenConnection.framework
     http://dev.renren.com上注册人人网开放平台应用，并将相关信息填写到以下字段
     **/
    [ShareSDK connectRenRenWithAppId:@"226427"
                              appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
                           appSecret:@"f29df781abdd4f49beca5a2194676ca4"
                   renrenClientClass:[RennClient class]];
}

- (void)dealloc
{
    
//    [_rootView release];
//    [_imageViewG release];
//    [_imageViewA release];
//    [_imageViewM release];
//    [_imageViewE release];
//    [_imageViewB release];
//    [_imageViewO release];
//    [_imageViewS release];
//    [_imageViewSS release];
    [_window release];
    [super dealloc];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
